from typing import List
from common.enum.strategy_group_enum import StrategyGroup
from common.enum.strategy_type_enum import StrategyType
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_assessment import RiskAssessment
from dto.strategy_info import StrategyInfoMetadata
from dto.strategy_stock_day import StrategyStockDay
from service.strategy.base_strategy import BaseStrategy


class TwoDaysBigBullishCandleStrategy(BaseStrategy):
    """
    关注策略：分析某个股票在前两个交易日是否都是大阳线（即收盘价大于开盘价且涨幅较大）。
    """

    def analyze(self, trade_info_list: List[StrategyStockDay]) -> RiskAssessment:
        """
        分析股票的前两个交易日是否都是大阳线。
        大阳线定义：收盘价大于开盘价，且当天涨幅大于2%。
        """
        node_point = 0
        description = ""

        # 确保至少有2天的交易数据
        if len(trade_info_list) >= 2:
            # 获取最后两天的交易数据
            last_two_days = trade_info_list[-2:]

            # 判断前两个交易日是否都是大阳线
            for i, day in enumerate(last_two_days):
                # 大阳线条件：收盘价大于开盘价且涨幅大于2%
                if day.close > day.open and (day.close - day.open) / day.open > 0.02:
                    node_point += 2  # 每天大阳线得分 +2
                    description += f"第{len(trade_info_list) - 2 + i}天：大看涨蜡烛（收盘>开盘，上涨>2%） "

        return RiskAssessment(
            stock_code=trade_info_list[0].stock_code,
            description=description,
            config=self.strategyConfig(),
            node_point=node_point,
        )

    def strategyConfig(self) -> StrategyInfoMetadata:
        """
        返回策略的配置
        """
        return StrategyInfoMetadata(
            strategy_code="two_days_big_bullish_candle",
            strategy_name="前两天大阳线",
            strategy_group=StrategyGroup.ATTENTION,  # 关注型策略
            strategy_type=StrategyType.PRICE,  # 根据价格类型
            analysis_day=2,
            strategy_level=2,
        )
